package models

import "github.com/spf13/viper"

type MysqlConf struct {
	Username string
	Password string
	Host     string
	Port     int
	Database string
}
type RedisConf struct {
	Host string
	Port int
	DB   int
}
type EsConf struct {
	Host string
	Port int
}

var (
	MysqlConfig MysqlConf
	RedisConfig RedisConf
	EsConfig    EsConf
)

func InitViper() {
	path := "./etc/dev.yaml"
	viper.SetConfigFile(path)
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
	MysqlConfig.Username = viper.GetString("MysqlConf.Username")
	MysqlConfig.Password = viper.GetString("MysqlConf.Password")
	MysqlConfig.Host = viper.GetString("MysqlConf.Host")
	MysqlConfig.Port = viper.GetInt("MysqlConf.Port")
	MysqlConfig.Database = viper.GetString("MysqlConf.Database")
	RedisConfig.Host = viper.GetString("RedisConf.Host")
	RedisConfig.Port = viper.GetInt("RedisConf.Port")
	RedisConfig.DB = viper.GetInt("RedisConf.DB")
	EsConfig.Host = viper.GetString("EsConf.Host")
	EsConfig.Port = viper.GetInt("EsConf.Port")
}
